<template>
<div class="activity-body">
  <div class="activity-ad">
  </div>
  <div class="activity-wrap">
    <div class="box-ready">
      <div class="prizeBox">
        <div class="prizeItem">
          <div class="prize-title">一等奖</div>
          <div class="prize-tip">获得价值1999元美的空调</div>
          <div class="prize-num">参考价：1999元</div>
          <img class="prize-img prize1" src="./img/rankprize1.png" alt="">
        </div>
        <div class="prizeItem">
          <div class="prize-title">二等奖</div>
          <div class="prize-tip">获得价值699元格力空调扇</div>
          <div class="prize-num">参考价：699元</div>
          <img class="prize-img prize2" src="./img/rankprize2.png" alt="">
        </div>
        <div class="prizeItem">
          <div class="prize-title">三等奖</div>
          <div class="prize-tip">获得价值499元车载冰箱</div>
          <div class="prize-num">参考价：499元</div>
          <img class="prize-img prize3" src="./img/rankprize3.png" alt="">
        </div>
        <div class="clearbox"></div>
      </div>
      <div class="no-ready" v-if="rankStep === 0">
        <img src="./img/rankwait.png" alt="">
        <div>数据加载中，请耐心等待～</div>
      </div>
      <ActivityRank style="margin-top: 30px;" :isInner="true" :showNum='10' v-else></ActivityRank>
      <div class="rule-box">
        <div class="rule-title">活动声明</div>
        <div class="rule-content">
          <div class="p1">
            <div class="p-title">1.活动时间：</div>
            <div class="p-content">
              <p>7月1日-7月31日。</p>
            </div>
          </div>
        </div>
      </div>
      <div class="rule-box">
        <div class="rule-title">活动规则</div>
        <div class="rule-content">
          <p class="p2">整个7月购买优刃任何产品即可参与冲榜活动</p>
          <p class="p2">第一名 获得价值1999元美的空调</p>
          <p class="p2">第二名至第五名 获得价值699元格力空调扇</p>
          <p class="p2">第六名至第十名 获得价值499元车载冰箱</p>
          <p class="p2">凡是7月参加购买优刃产品的客户皆可获得一台刀具联盟定制手持小风扇。</p>
          <p class="p2">注：每个账号限领一次</p>
          <p class="p2">本活动解释权归刀具联盟所有</p>
        </div>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import {ActivityRank} from '@/components/index'
import {mapState, mapActions} from 'vuex'
import { phoneReplace } from '@/tool/tool'
export default {
  components: {
    ActivityRank
  },
  computed: {
    ...mapState({
      activityRankData: (state) => {
        return state.activity.activityRank
      },
      userName: (state) => {
        return state.user.username
      },
      rankPopList () {
        let len = this.activityRankData.overRanks && this.activityRankData.overRanks.length
        let overRanks = this.activityRankData.overRanks
        this.myRankList = overRanks && overRanks[len - 1]['myRank']
        // let list = (overRanks && overRanks[len - 1]['rankDetailVOS'] && overRanks[len - 1]['rankDetailVOS'].slice(0, 3)) || []
        return (overRanks && overRanks[len - 1]['rankDetailVOS'] && overRanks[len - 1]['rankDetailVOS'].slice(0, 3)) || []
      }
    })
  },
  data () {
    return {
      activeGoods: {},
      activityId: '',
      activityList: [],
      timerText: '',
      timerresult: '',
      openedActList: {},
      actDate: '',
      rankStep: 0,
      myRankList: null
    }
  },
  methods: {
    ...mapActions(['getActivityRank']),
    // 第一次进入获取一次rankdata
    getRank () {
      let _this = this
      this.getActivityRank(10).then(function (res) {
        _this.setRank()
      })
    },
    // 处理rankdata
    setRank () {
      // 没有未开始的活动
      let rankActivityList = {}
      if (this.activityRankData.openRanks && !this.activityRankData.openRanks.length) {
        rankActivityList = this.activityRankData.overRanks[0]
        this.rankStep = 2
        return
      }
      rankActivityList = this.activityRankData.openRanks[0] || {}
      // 样式
      let startTimeParm = rankActivityList.startTime
      let endTimeParm = rankActivityList.endTime
      const starTimeStamp = (new Date(startTimeParm.replace(/-/g, '/'))).getTime()
      const endTimeStamp = (new Date(endTimeParm.replace(/-/g, '/'))).getTime()
      let nowTime = (new Date()).getTime()
      // 周周活动开始
      if (nowTime > starTimeStamp && nowTime <= endTimeStamp) {
        this.rankStep = 1
        return
      }
      // 周周活动还未开始
      if (nowTime < starTimeStamp) {
        this.rankStep = 0
      }
      // 周周活动结束
      if (nowTime > endTimeStamp) {
        this.rankStep = 2
      }
    }
  },
  mounted () {
    this.getRank()
  },
  filters: {
    phoneReplace,
    nicknameReplace (value, isMe) {
      if (isMe || (value && value.length === 1)) { return value }
      let len = value.length
      let hiddenStr = value.substring(2, len)
      if (len === 2) {
        return value.replace(/.{0,1}$/, '*')
      } else if (len > 2) {
        return value.replace(hiddenStr, '****')
      }
    }
  },
  watch: {
    activityRankData (newVal) {
      if (newVal) {
        this.setRank()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.activity-body{
  background-color: #ffe1e1;
  padding-bottom: 30px;
}
.activity-ad{
  width: 100%;
  height: 600px;
  background-image: url("./img/rankbanner.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  position: relative;
  .rank-tabbox{
    width: 100%;
    bottom: 2px;
    position: absolute;
    .rank-tabs{
      width: 1000px;
      margin: 0 auto;
      font-size: 0;
      overflow: hidden;
      border-radius: 20px 20px 0 0 / 20px 20px 0 0;
      background-color: #f39f5f;
      .rank-tab{
        width:25%;
        height:90px;
        border: none;
        background: linear-gradient(left, #f39f5f, #f78d3e);
        display: inline-block;
        float: left;
        div{
          font-size: 16px;
          color: #666666;
          text-align: center;
          margin-top: 10px;
          &:first-of-type{
            font-size: 18px;
            margin-top: 20px;
            color: #333333;
          }
        }
        &.active{
          background: #FFD7CD;
          div{
            color: #810101;
          }
        }
        &.over{
          background: #FF9A80;
          div{
            color: #9B5E4E;
          }
        }
      }
    }
  }
}
.activity-wrap{
  width: 1020px;
  margin: 0 auto;
  .prizeBox{
    margin-top: 30px;
    .prizeItem{
      width: 320px;
      height: 400px;
      background: url(./img/rankprizebg.png);
      background-size: 100% 100%;
      box-shadow:0px 5px 15px 0px rgba(255,127,113,1);
      border-radius: 20px;
      float: left;
      margin: 0 10px;
      margin-bottom: 20px;
      text-align: center;
      color: #fff;
      position: relative;
      .prize-title{
        font-size: 25px;
        margin-top: 45px;
        font-weight: 500;
      }
      .prize-tip{
        font-size: 20px;
        margin-top: 20px;
      }
      .prize-num{
        width: 100%;
        font-size: 12px;
        margin-top: 10px;;
        text-align: center;
      }
      .prize-img{
        &.prize1{
          width: 220px;
        }
        &.prize2{
          width: 55px;
          margin-top: 30px;
        }
        &.prize3{
          width: 180px;
          margin-top: 20px;
        }
      }
      img{
        margin-top: 47px;
        width: 210px;
      }
    }
    .clearbox{ 
      clear: both;
    }
  }
  .no-ready{
    background-color: #fff;
    border-radius: 6px;
    height: 340px;
    margin-top: 30px;
    text-align: center;
    font-size: 20px;
    color: #333333;
    img{
      width: 220px;
      margin-top: 40px;
    }
    div{
      margin-top: 13px;
    }
  }
  .rule-box{
    margin-top: 30px;
    border-radius: 6px;
    overflow: hidden;
    .rule-title{
      height: 60px;
      line-height: 60px;
      background-color: #E33939;
      color: #fff;
      box-sizing: border-box;
      padding-left: 30px;
    }
    .rule-content{
      width: 100%;
      box-sizing: border-box;
      padding: 30px;
      display: inline-block;
      background-color: #fff;
      font-size: 14px;
      .p-title{
        display: inline-block;
        vertical-align: top;
        line-height: 30px;
        color: #666666;
      }
      .p-content{
        display: inline-block;
        line-height: 30px;
      }
      .p2{
        color: #666666;
        line-height: 30px;
        span{
          color:#333333;
        }
      }
    }
  }
  .box-over{
    .over-item{
      height: 400px;
      box-sizing: border-box;
      border: 20px solid #CF2121;
      background-color: #fff;
      box-shadow:0px 6px 8px 0px rgba(255,64,45,0.5);
      border-radius:8px;
      padding: 77px 077px 80px;
      margin-top: 30px;
      position: relative;
      .over-title{
        color: #CF2121;
        font-size: 40px;
      }
      .over-cost{
        margin-top: 10px;
        font-size: 20px;
        line-height: 40px;
        color: #CF2121;
        span{
          font-size: 40px;
        }
      }
      .over-user{
        width: 400px;
        height: 70px;
        background-color: #CF2121;
        color: #fff;
        font-size: 20px;
        box-sizing: border-box;
        padding-left: 34px;
        line-height: 70px;
        border-radius: 6px;
        margin-top: 25px;
      }
      .over-imgbox{
        width: 300px;
        position: absolute;
        right: 60px;
        bottom: 0;
        text-align: center;
        .over-imgtip{
          margin-top: 11px;
          font-size: 16px;
          color: #2D2D2D;
        }
      }
      &:nth-of-type(1){
        .over-imgbox{
          bottom: 24px;
          img{
            width: 135px;
          }
        }
      }
      &:nth-of-type(2){
        .over-imgbox{
          bottom: 62px;
          img{
            width: 277px;
          }
        }
      }
      &:nth-of-type(3){
        .over-imgbox{
          bottom: 64px;
          img{
            width: 267px;
          }
        }
      }
    }
    .own-item{
      margin-top: 30px;
      line-height:100px;
      background:linear-gradient(209deg,rgba(233,119,69,1) 0%,rgba(207,33,33,1) 100%);
      border-radius:6px;
      padding: 0 40px;
      color: #ffffff;
      .title{
        font-size:32px;
      }
      .amount{
        float: right;
        font-weight:500;
        font-size:40px;
      }
    }
    .over-tel{
      box-sizing: border-box;
      padding: 20px 20px 0;
      margin-top: 20px;
      font-size: 20px;
      div{
        &:nth-of-type(2){
          margin-top: 20px;
          a{
            color: #0078D8;
            &:nth-of-type(2){
              margin-left: 20px;
            }
          }
        }
      }
    }
  }
}

</style>
